package com.qsd.doc4jsimpple.item;

import com.qsd.doc4jsimpple.style.DocxStyle;
import com.qsd.doc4jsimpple.util.RichTextHelper;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import org.apache.commons.lang3.StringUtils;

import java.io.IOException;

/**
 */
@Getter
@Setter
@RequiredArgsConstructor
public class DocxImage extends DocxItem {

    /**
     * 字节
     */
    private final byte[] bytes;

    /**
     * 文件名提示
     */
    private String fileNameHint = "";

    /**
     * alt文本
     */
    private String altText = "";

    /**
     * 宽度
     */
    private Long width;

    /**
     * 高度
     */
    private Long height;

    private String fileUrl;




    public DocxImage(byte[] bytes, DocxStyle style) {
        super(style);
        this.bytes = bytes;
    }

    public byte[] getBytes() {
        if(StringUtils.isNotEmpty(fileUrl)){
            byte[] imageBytes = null;
            try {
                imageBytes = RichTextHelper.fetchFileFromServer(fileUrl);
            } catch (Exception e) {
               e.printStackTrace();
            }
            return imageBytes;
        }
        return bytes;
    }
}
